草庐IT

ASP.NET MVC : Save multiple values on autocomplete

全部标签

c# - ASP.NET Core 的 ActionFilterAttribute 中的异步 OnActionExecuting

ASP.NETCore的ActionFilterAttribute有这些:publicvirtualvoidOnActionExecuting(ActionExecutingContextcontext);publicvirtualvoidOnActionExecuted(ActionExecutedContextcontext);publicvirtualTaskOnActionExecutionAsync(ActionExecutingContextcontext,ActionExecutionDelegatenext);我需要OnActionExecuting的异步版本,它不存在

c# - 如何在 asp.net 中将参数添加到操作过滤器?

我有以下过滤器属性,我可以像这样将一个字符串数组传递给属性[MyAttribute("string1","string2")]。publicclassMyAttribute:TypeFilterAttribute{privatereadonlystring[]_ids;publicMyAttribute(paramsstring[]ids):base(typeof(MyAttributeImpl)){_ids=ids;}privateclassMyAttributeImpl:IActionFilter{privatereadonlyILogger_logger;publicMyAttr

c# - 使用 asp.net 发送邮件以及嵌入的图像

使用asp.net发送带有嵌入图像的邮件我已经用过following,但是没用DimEMAsSystem.Net.Mail.MailMessage=NewSystem.Net.Mail.MailMessage(txtFrom.Text,txtTo.Text)DimAAsSystem.Net.Mail.Attachment=NewSystem.Net.Mail.Attachment(txtImagePath.Text)DimRGenAsRandom=NewRandom()A.ContentId=RGen.Next(100000,9999999).ToString()EM.Attachme

c# - 在 ASP.NET MVC 中的 ViewModel 类上使用 Bind 属性

为什么开发人员可能会在ASP.NETMVC项目中对ViewModel对象使用Bind属性,这会对应用程序产生不利影响吗?[Bind(Include="Id,Name")][MetadataType(typeof(MyViewModelValidation))]publicclassMyViewModel{publicstringCustomerProductUserName{get;set;}[Display(Name="Name")]publicstringName{get;set;}}publicclassMyViewModelValidation{[HiddenInput(Dis

c# - 将查询参数绑定(bind)到 ASP.NET Core 中的模型

我正在尝试使用从查询参数到搜索对象的模型绑定(bind)。我的搜索对象是[DataContract]publicclassCriteria{[DataMember(Name="first_name")]publicstringFirstName{get;set;}}我的Controller有以下Action[Route("users")]publicclassUserController:Controller{[HttpGet("search")]publicIActionResultSearch([FromQuery]Criteriacriteria){...}}当我按如下方式调用端

c# - 如何为 ASP.NET Core 中的单元/集成测试模拟 IFormFile?

我想编写用于在ASP.NETCore中上传文件的测试,但似乎找不到一种很好的方法来模拟/实例化从IFormFile派生的对象。关于如何做到这一点有什么建议吗? 最佳答案 假设你有一个Controller,比如......publicclassMyController:Controller{publicTaskUploadSingle(IFormFilefile){...}}...使用被测方法访问IFormFile.OpenReadStream()。从ASP.NETCore3.0开始,使用FormFileClass的实例现在是IFor

c# - ASP.NET MVC 4,EF5,模型中的唯一属性 - 最佳实践?

ASP.NETMVC4、EF5、代码优先、SQLServer2012Express在模型中实现唯一值的最佳做法是什么?我有一个places类,它有一个“url”属性,每个地方都应该是唯一的。publicclassPlace{[ScaffoldColumn(false)]publicvirtualintPlaceID{get;set;}[DisplayName("DateAdded")]publicvirtualDateTimeDateAdded{get;set;}[Required(ErrorMessage="PlaceNameisrequired")][StringLength(10

c# - 我的 Asp.Net C# 类如何返回 json 格式

如何想要一个返回json格式的类。这个方法在Controller中很有效但是当我想放入一个类时,Json对象似乎不存在。publicJsonResultTest(){//Error1Thename'Json'doesnotexistinthecurrentcontextC:\inetpub\wwwroot\mvcinfosite\mvcinfosite\Validation\ValidationClass\BaseValidator.cs6620mvcinfositereturnJson(new{errMsg="test"});}我想将该代码放在一个简单的类中。我希望能够在许多Cont

c# - ASP.NET Identity 2.0 检查当前用户是否在角色 IsInRole

使用ASP.NETIdentity2.0如何检查当前登录的用户是否在某个角色中?我正在使用以下内容,但想知道是否有更有效的方法。varum=newUserManager(newUserStore(newDbContext()));varau=um.FindByEmail(Context.User.Identity.GetUserName());varinrole=um.IsInRole(au.Id,"Admin");if(inrole){} 最佳答案 ASPIdentity中的正确方法很简单User.IsInRole("rolena

c# - 如何更改 URL 中的 ASP.NET MVC Controller 名称?

如果我们有"example_name",我们可以使用[ActionName("")]在url中更改它所以,我想为Controller名称执行此操作。我能做到:ControllerName>example_nameController>在URL中:"/example_controller"我想在URL中像这样更改Controller名称:"/example-conroller" 最佳答案 您需要使用AttributeRouting,MVC5中引入的功能。根据您的示例,您应该按如下方式编辑您的Controller:[RoutePrefi